<template>
  <div id="alllist">
    <el-dialog
      title="设置"
      :visible.sync="setupFormVisible"
      width="600px" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="setupForm" label-width="200px" ref="setupForm" :inline="true" v-if="!setupFormLoading">
        <el-form-item prop="status" label="填报状态">
          <el-radio-group v-model="setupForm.status">
            <el-radio :label="true">开启</el-radio>
            <el-radio :label="false">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="status" label="工作月份（批次）" v-if="setupForm.status">
          <el-date-picker
            v-model="setupForm.yearMonth"
            type="month"
            placeholder="选择月"
            style="width:150px"
            value-format="yyyy-MM"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click.native="setupFormSubmit()" :loading="setupFormSubmitLoading">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      title="设置"
      :visible.sync="setupAdminFormVisible"
      width="600px" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="setupAdminForm" label-width="100px" ref="setupForm" :inline="true" v-if="!setupFormLoading">
        <el-form-item prop="status" label="用户">
          <el-select v-model="setupAdminForm.ids" placeholder="请选择" style="width:300px" multiple>
            <el-option v-for="(item,index) in users" :key="index" :label="item.truename" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click.native="setupAdminFormSubmit()" :loading="setupFormSubmitLoading">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :title="dialogtitle"
      :visible.sync="porjectEidtFormVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <projectEdit @dialogHide="saveSuccess" :projectId="projectId" :readOnly="readonly" :timestamp="timestamp" :showUnit="showUnit" :isDown="downFlag" :isAdmin="!downFlag"></projectEdit>
    </el-dialog>
    <el-dialog
      title="上报情况"
      :visible.sync="personListVisible"
      width="810px" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <section class="wboxd" style="width:751px">
        <el-table :data="personList" highlight-current-row v-loading="personlistLoading" @sort-change='sortChange' border>
          <el-table-column type="index" width="50" align="center" class-name="tableth" label="序号" >
          </el-table-column>
          <!-- <el-table-column label="处室" width="200" prop="deptName">
            <template slot-scope="scope">
              {{scope.row.deptName}}
            </template>
          </el-table-column> -->
          <el-table-column label="姓名" width="250" prop="userName">
            <template slot-scope="scope">
              {{scope.row.userName}}
            </template>
          </el-table-column>
          <el-table-column label="上报状态" width="200" prop="workType">
            <template slot-scope="scope">
              {{scope.row.dataUpdateDatetime?"已上报":"未上报"}}
            </template>
          </el-table-column>
          <el-table-column label="上报时间" width="250" prop="workType">
            <template slot-scope="scope">
              {{scope.row.dataUpdateDatetime}}
            </template>
          </el-table-column>
        </el-table>
      </section>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/workRecord' }">工作日志</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
        <el-form :inline="true" :model="filters">
          <div>
            <div style="color:red;margin-bottom:10px;">{{instruction}}</div>
            <el-radio-group v-model="mySelfFlag" @change="changeFlag" style="margin-right:0;" v-if="workRecordAdmin">
              <el-radio-button :label="1">本处室</el-radio-button>
              <el-radio-button :label="2">全部处室</el-radio-button>
            </el-radio-group>
            <el-form-item v-if="myRole===1||myRole===2" style="margin-right:0;">
              <el-select v-model="filters.state" placeholder="请选择" style="width:120px">
                <el-option label="全部状态" :value="2"></el-option>
                <el-option label="未上报司长" :value="1"></el-option>
                <el-option label="司内流转" :value="5"></el-option><!--202106状态值上报司长由4改为5-->
                <el-option label="下发" :value="6"></el-option><!--202106状态值下发由5改为6-->
              </el-select>
            </el-form-item>
            <el-form-item label="" style="margin-right:0;">
              <el-input v-model="filters.workPlan" placeholder="关键词" style="width:100px" />
            </el-form-item>
            <el-form-item style="margin-right:0;">
              <el-select v-model="filters.workType" placeholder="请选择" style="width:120px">
                <el-option label="全部类型" :value='null'></el-option>
                <el-option v-for="(item,index) in workTypeList" :key="index" :label="item.deleted?item.label+'(已停用)':item.label" :value="item.label"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-right:0;">
              <el-select v-model="filters.completeStatus" placeholder="请选择" style="width:110px">
                <el-option label="全部完成状态" :value='null'></el-option>
                <el-option label="未完成" :value="1"></el-option>
                <el-option label="完成" :value="2"></el-option>
                <el-option label="结束" :value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-right:0;">
              <el-select v-model="filters.selectDep" placeholder="请选择" style="width:120px">
                <el-option label="全部处室" value=''></el-option>
                <el-option v-for="(item,index) in manageDep" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-date-picker
              v-model="filters.year"
              type="year"
              placeholder="选择年"
              style="width:100px"
              value-format="yyyy"
            >
            </el-date-picker>
            <el-select v-model="filters.month" placeholder="请选择" style="width:100px">
              <el-option label="全年" :value='0'></el-option>
              <el-option label="1月" :value="1"></el-option>
              <el-option label="2月" :value="2"></el-option>
              <el-option label="3月" :value="3"></el-option>
              <el-option label="4月" :value="4"></el-option>
              <el-option label="5月" :value="5"></el-option>
              <el-option label="6月" :value="6"></el-option>
              <el-option label="7月" :value="7"></el-option>
              <el-option label="8月" :value="8"></el-option>
              <el-option label="9月" :value="9"></el-option>
              <el-option label="10月" :value="10"></el-option>
              <el-option label="11月" :value="11"></el-option>
              <el-option label="12月" :value="12"></el-option>
              <el-option label="一季度" :value="13"></el-option>
              <el-option label="二季度" :value="14"></el-option>
              <el-option label="三季度" :value="15"></el-option>
              <el-option label="四季度" :value="16"></el-option>
            </el-select>
            <el-form-item style="margin-right:0">
              <el-tooltip class="item" effect="dark" content="查询" placement="top">
                <el-button circle type="primary" @click="searchPrj" icon="el-icon-search"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="margin-right:0">
              <el-tooltip class="item" effect="dark" content="导出Excel" placement="top">
                <el-button circle type="success" @click="exportExcel" icon="el-icon-download"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="float:right;margin-right:5px">
              <el-tooltip class="item" effect="dark" content="设置综合处日志汇总上报司长工作权限" placement="top" v-if="myRole===2&&unitName==='综合处'">
                <el-button circle type="primary" @click="setupAdmin()" icon="el-icon-user"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="float:right;margin-right:5px">
              <el-tooltip class="item" effect="dark" content="设置填报状态和工作月份" placement="top" v-if="workRecordAdmin">
                <el-button circle type="success" @click="setup()" icon="el-icon-setting"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="float:right;margin-right:5px">
              <el-tooltip class="item" effect="dark" content="查看各主管副司长上报情况" placement="top" v-if="status">
                <el-button circle type="primary" @click="showPersonList()" icon="el-icon-s-order"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="float:right;margin-right:5px">
              <el-tooltip class="item" effect="dark" content="上报司长" placement="top" v-if="status&&!reported">
                <el-button circle type="success" @click="submitToSZ" icon="el-icon-upload2"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item style="float:right;margin-right:5px">
              <el-tooltip class="item" effect="dark" :content="isDown?'录入下发工作日志':'综合处整理录入'" placement="top" >
                <el-button circle type="primary" @click="addnew" icon="el-icon-plus"></el-button>
              </el-tooltip>
            </el-form-item>
          </div>
        </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <h1>日志列表</h1>
      <el-table :data="prjs" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
        <el-table-column type="index" width="50" fixed align="center" class-name="tableth" label="序号" >
        </el-table-column>
        <el-table-column type="selection" width="45" fixed :selectable="canSelect">
        </el-table-column>
        <el-table-column label="批次" width="90" prop="beginDate">
          <template slot-scope="scope">
            {{scope.row.beginDate?scope.row.beginDate.substring(0,7):''}}
          </template>
        </el-table-column>
        <el-table-column label="类型" width="100" prop="workType">
          <template slot-scope="scope">
            {{scope.row.workType}}
          </template>
        </el-table-column>
        <el-table-column prop="workPlan" label="工作事项" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="司内流转" placement="top" v-if="scope.row.state===5||scope.row.state===6">
              <i class="el-icon-star-on" style="font-size:1.2rem;color:#f90;margin-right:5px;"></i>
            </el-tooltip>{{scope.row.workPlan}}
          </template>
        </el-table-column>
        <el-table-column prop="respDept" label="责任处室" show-overflow-tooltip width="100">
          <template slot-scope="scope">
            {{scope.row.respDept==='司领导'?'':scope.row.respDept}}
          </template>
        </el-table-column>
        <el-table-column prop="respUserName" label="责任人" show-overflow-tooltip width="150">
          <template slot-scope="scope">
            {{scope.row.respUserName}}
            <el-popover
              placement="right"
              width="452"
              trigger="click"
              v-if="scope.row.hasOtherRespUser"
              >
              <el-table :data="otherRespUsers" v-loading="otherRespUsersLoading" border style="border-left:1px solid #74a6cc;border-top:1px solid #74a6cc;border-bottom:1px solid #74a6cc;">
                <el-table-column width="150" property="respUserName" label="其他责任人"></el-table-column>
                <el-table-column width="150" property="respDept" label="责任部门"></el-table-column>
                <el-table-column width="150" property="completeStatus" label="完成情况">
                  <template slot-scope="subscope">
                    <i class="el-icon-info" style="color:#67C23A;font-size:1.2rem" v-if="subscope.row.completeStatus===2" />
                    <i class="el-icon-info" style="color:#ccc;font-size:1.2rem" v-if="subscope.row.completeStatus===3" />
                    {{completeStatusText(subscope.row.completeStatus)}}
                  </template>
                </el-table-column>
                <!-- <el-table-column width="200" property="completeTime" label="完成时间"></el-table-column> -->
              </el-table>
              <i slot="reference" class="el-icon-zoom-in" style="cursor:pointer" @click="showOtherRespUser(scope.row.id)" />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="预计完成时限" show-overflow-tooltip width="200">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" :content="'距离完成时限还有'+scope.row.overdue+'天'" placement="top" v-if="scope.row.overdue<=3&&scope.row.overdue>=0&&scope.row.completeStatus===1">
              <i class="icon_flash" />
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="'已超出完成时限'+(-scope.row.overdue)+'天'" placement="top" v-if="scope.row.overdue<0&&scope.row.completeStatus===1">
              <i class="icon_flash1" />
            </el-tooltip>
            {{scope.row.endDate}}
          </template>
        </el-table-column>
        <el-table-column prop="completeStatus" label="完成情况" width="150">
          <template slot-scope="scope">
            <!-- <el-tooltip class="item" effect="dark" content="已超出预计完成时限" placement="top" v-if="scope.row.overdue">
              <i class="el-icon-info" style="color:#F56C6C;font-size:1.2rem" />
            </el-tooltip> -->
            <el-tooltip class="item" effect="dark" :content="'完成时间：'+scope.row.completeTime+limitTest(scope.row)" placement="top" v-if="scope.row.completeStatus===2" >
              <i class="el-icon-info" style="color:#67C23A;font-size:1.2rem"/>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="'结束时间：'+scope.row.completeTime+limitTest(scope.row)" placement="top" v-if="scope.row.completeStatus===3" >
              <i class="el-icon-info" style="color:#ccc;font-size:1.2rem"/>
            </el-tooltip>
            {{completeStatusText(scope.row.completeStatus)}}
          </template>
        </el-table-column>
        <el-table-column prop="state" label="状态" width="150">
          <template slot-scope="scope">
            <i class="el-icon-s-goods" style="font-size:1.2rem;color:#e6a23c;margin-right:5px;" v-if="scope.row.state===6"></i><!--202106状态值下发由5改为6-->{{stateText(scope.row.state)}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="small" @click="editPrj(scope.row.id,scope.row.state)" type="text" icon="el-icon-edit" v-if="canEdit(scope.row)">编辑</el-button>
            <el-button size="small" @click="detailPrj(scope.row.id,scope.row.state)" type="text" icon="el-icon-search" v-if="!canEdit(scope.row)">查看</el-button>
            <el-button size="small" @click="del(scope.row.id)" type="text" icon="el-icon-delete" v-if="canEdit(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    <div class="block">
      <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      <div id="recordLegent">
        <!-- <div><b>图例：</b></div> -->
        <i class="el-icon-star-on" style="font-size:1.2rem;color:#f90;margin:10px 0 0;width:20px"></i><div>司内流转</div>
        <i class="el-icon-s-goods" style="font-size:1.2rem;color:#e6a23c;margin:10px 0 0 20px;width:20px"></i><div>下发</div>
        <i class="icon_flash" style="width:20px;margin-left:20px" /><div>距离完成时限3日内</div>
        <i class="icon_flash1" style="width:20px;margin-left:20px"></i><div>超出完成时限</div>
        <div style="margin-left:20px;"><span style="color:red">红字记录</span> 之前批次未完成</div>
      </div>
    </div>
    </section>
  </div>
</template>

<script>
import projectEdit from './detail'
export default {
  components: {
    projectEdit
  },
  data () {
    return {
      downFlag: true,
      isDown: true,
      reported: true,
      instruction: '',
      workRecordAdmin: false,
      setupAdminFormVisible: false,
      setupAdminFormLoading: false,
      searchEndDate: '',
      searchBeginDate: '',
      searchText: '',
      setupFormVisible: false,
      setupForm: {
        status: '',
        yearMonth: ''
      },
      setupFormLoading: false,
      setupFormSubmitLoading: false,
      status: false,
      unitName: '',
      mySelfFlag: 2,
      myMonth: '',
      personList: [],
      personListVisible: false,
      personlistLoading: false,
      ids: [],
      formShowVisible: false,
      showUnit: false,
      readonly: true,
      prjs: [],
      projectId: null,
      dialogtitle: '新建下发工作日志',
      timestamp: '',
      porjectEidtFormVisible: false,
      porjectEidtFormLoading: false,
      porjectEidtForm: {
        beginDate: '',
        endDate: '',
        fileId: '',
        projectId: '',
        title: '',
        unitIds: []
      },
      filters: {
        year: '',
        month: '',
        state: 2,
        selectDep: '',
        workType: null,
        workPlan: '',
        completeStatus: null
      },
      total: 0,
      pageNum: 1,
      pageSize: 20,
      listLoading: false,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      changeSizeFlag: false,
      tableHeight: 100,
      statedic: [
        {id: 1, name: '处内人员'},
        {id: 2, name: '处长'},
        {id: 3, name: '主管副司长'},
        {id: 4, name: '综合处'},
        {id: 5, name: '司长'},
        {id: 6, name: '下发'}
      ],
      myloading: false,
      myRole: 0,
      manageDep: [],
      workTypeList: [],
      otherRespUsers: [],
      otherRespUsersLoading: false,
      setupAdminForm: {ids: []},
      users: []
    }
  },
  methods: {
    showOtherRespUser (id) {
      this.otherRespUsersLoading = true
      this.$http.get(this.$http.defaults.workRecordAPI + `api/record/queryRespUser?workRecordId=` + id).then(response => {
        if (response.data.success === true) {
          this.otherRespUsersLoading = false
          this.otherRespUsers = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    tableRowClassName ({row, rowIndex}) {
      if (new Date(row.beginDate) < this.searchBeginDate) {
        return 'work-record-warning-row'
      }
      return ''
    },
    setupFormSubmit () {
      let para = {
        yearMonth: this.setupForm.status ? this.setupForm.yearMonth : ''
      }
      if (this.setupForm.status && (!this.setupForm.yearMonth || this.setupForm.yearMonth === '')) {
        this.$message({
          message: '填报开启状态下请填写工作月份',
          type: 'error'
        })
        return false
      }
      this.setupFormSubmitLoading = true
      this.$http.post(this.$http.defaults.workRecordAPI + `api/config/saveConfig`, para).then(response => {
        if (response.data.success === true) {
          this.$message({
            message: '提交成功！',
            type: 'success'
          })
          this.setupFormVisible = false
          this.loadSetup()
        } else {
          console.log('提交失败:' + response.data.message)
          this.$message({
            message: '提交失败:' + response.data.message,
            type: 'error'
          })
        }
        this.setupFormSubmitLoading = false
      })
    },
    setupAdminFormSubmit () {
      let para = {
        ids: this.setupAdminForm.ids
      }
      this.setupAdminFormSubmitLoading = true
      this.$http.post(this.$http.defaults.workRecordAPI + `api/manageuser/updateManageUsers`, para).then(response => {
        if (response.data.success === true) {
          this.$message({
            message: '提交成功！',
            type: 'success'
          })
          this.setupAdminFormVisible = false
          this.loadSetupAdmin()
        } else {
          console.log('提交失败:' + response.data.message)
          this.$message({
            message: '提交失败:' + response.data.message,
            type: 'error'
          })
        }
        this.setupAdminFormSubmitLoading = false
      })
    },
    setup () {
      this.setupFormVisible = true
      this.loadSetup()
    },
    setupAdmin () {
      this.setupAdminFormVisible = true
      this.loadSetupAdmin()
    },
    limitTest (row) {
      if (row.completeTime > row.endDate) {
        return '（超出时限）'
      } else {
        return ''
      }
    },
    getDics (code, listname) {
      this.$http
        .get(this.$http.defaults.workRecordAPI + `api/dict/getByCode?code=` + code)
        .then(response => {
          if (response.data.success) {
            this[listname] = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      let para = {
        unitName: '综合处',
        userIdentity: 1
      }
      this.$http
        .post(this.$http.defaults.workRecordAPI + `api/record/findUserByIdentityAndUnit`, para)
        .then(response => {
          if (response.data.success) {
            this.users = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    changeFlag () {
      if (this.mySelfFlag === 2) {
        this.$router.push({path: '/workRecord/allList'})
      } else if (this.mySelfFlag === 1) {
        this.$router.push({path: '/workRecord'})
      }
    },
    showPersonList () {
      this.personListVisible = true
      this.personlistLoading = true
      this.$http.post(this.$http.defaults.workRecordAPI + `api/record/queryFszReportList`, {}).then(response => {
        if (response.data.success === true) {
          this.personList = response.data.result
          // this.manageDep = this.personList.map(item => item.deptName)
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
        this.personlistLoading = false
      })
    },
    // 获取全部单位列表
    getDeptList () {
      this.$http.post(this.$http.defaults.workRecordAPI + `api/record/queryCzReportList`, {}).then(response => {
        if (response.data.success === true) {
          this.personList = response.data.result
          this.manageDep = this.personList.map(item => item.deptName)
          this.getList()
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    canSelect (row) {
      if (row.state === 4) { // 202106
        return true
      } else {
        return false
      }
    },
    canEdit (row) {
      if (row.state === 6 || row.state === 4) { // 202106
        return true
      } else {
        return false
      }
    },
    queryIfReported () {
      this.$http.get(this.$http.defaults.workRecordAPI + `api/record/getZhcczReportList`, {}).then(response => {
        if (response.data.success === true) {
          this.reported = response.data.result.length > 0
          if (this.reported) {
            this.instruction = '提示：综合处已将' + this.filters.year + '年' + this.filters.month + '月份工作日志汇总完成并上报司长'
            this.isDown = true
          } else {
            this.isDown = false
            this.instruction = '提示：综合处已启动' + this.filters.year + '年' + this.filters.month + '月份工作日志填报工作，点击“查看各主管副司长报综合处情况”按钮可查看各主管副司长的报综合处情况，请将工作日志列表中工作日志填写汇总完成后，将需要上报司长的工作日志，点击勾选日志列表前复选框后，再点击“上报司长”按钮上报司长（每月只能上报一次）'
          }
        } else {
          console.log('操作失败:' + response.data.message)
          this.$message({
            message: '操作失败:' + response.data.message,
            type: 'error'
          })
        }
        this.myloading = false
        this.getDeptList()
      })
    },
    submitToSZ () {
      if (this.ids.length > 0) {
        this.$confirm('确定将所选工作日志上报司长?', '提示', {
          type: 'success'
        }).then(() => {
          this.$http.post(this.$http.defaults.workRecordAPI + `api/record/submitRecordToSZ`, {ids: this.ids}).then(response => {
            if (response.data.success === true) {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
            } else {
              console.log('操作失败:' + response.data.message)
              this.$message({
                message: '操作失败:' + response.data.message,
                type: 'error'
              })
            }
            this.myloading = false
            this.queryIfReported()
            this.getList()
          })
        })
      } else {
        this.$message({
          message: '请至少选择一条信息',
          type: 'danger'
        })
      }
    },
    handleSelectionChange (val) {
      this.ids = val.map(item => item.id)
    },
    saveSuccess () {
      this.porjectEidtFormVisible = false
      this.getList()
    },
    addnew () {
      this.downFlag = this.isDown
      this.dialogtitle = this.isDown ? '新建下发工作日志' : '新建工作日志'
      this.projectId = 0
      this.readonly = false
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    detailPrj (id, state) {
      if (state === 6) {
        this.dialogtitle = '下发日志详情'
        this.downFlag = true
      } else {
        this.dialogtitle = '日志详情'
        this.downFlag = false
      }
      this.projectId = id
      this.readonly = true
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    editPrj (id, state) {
      if (state === 6) {
        this.dialogtitle = '编辑下发日志'
        this.downFlag = true
      } else {
        this.dialogtitle = '编辑日志'
        this.downFlag = false
      }
      this.projectId = id
      this.readonly = false
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    // 查询
    searchPrj () {
      this.pageNum = 1
      this.getList()
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = true
      } else {
        this.Isace = false
      }
      this.getList()
    },
    exportExcel () {
      if (!this.filters.year || this.filters.year === '') {
        this.$message({
          message: '请选择导出年月',
          type: 'error'
        })
        return false
      }
      if (this.filters.month === 0) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 0, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 12, 0))
        this.searchText = this.filters.year + '年 全年'
      } else if (this.filters.month > 0 && this.filters.month <= 12) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), this.filters.month - 1, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), this.filters.month, 0))
        this.searchText = this.filters.year + '年' + this.filters.month + '月'
      } else if (this.filters.month === 13) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 0, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 2, 31))
        this.searchText = this.filters.year + '年 第一季度'
      } else if (this.filters.month === 14) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 3, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 5, 30))
        this.searchText = this.filters.year + '年 第二季度'
      } else if (this.filters.month === 15) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 6, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 8, 30))
        this.searchText = this.filters.year + '年 第三季度'
      } else if (this.filters.month === 16) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 9, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 11, 31))
        this.searchText = this.filters.year + '年 第四季度'
      }
      let url = ''
      if (this.manageDep.indexOf('司领导') === -1) {
        this.manageDep.push('司领导')
      }
      let searchBeginDateMonth = this.searchBeginDate.getMonth() < 9 ? '0' + (this.searchBeginDate.getMonth() + 1) : this.searchBeginDate.getMonth() + 1
      let searchBeginDateDay = this.searchBeginDate.getDate() < 10 ? '0' + this.searchBeginDate.getDate() : this.searchBeginDate.getDate()
      let searchEndDateMonth = this.searchEndDate.getMonth() < 9 ? '0' + (this.searchEndDate.getMonth() + 1) : this.searchEndDate.getMonth() + 1
      let searchEndDateDay = this.searchEndDate.getDate() < 10 ? '0' + this.searchEndDate.getDate() : this.searchEndDate.getDate()
      let searchBeginDate = this.searchBeginDate.getFullYear() + '-' + searchBeginDateMonth + '-' + searchBeginDateDay
      let searchEndDate = this.searchEndDate.getFullYear() + '-' + searchEndDateMonth + '-' + searchEndDateDay
      url = this.$http.defaults.workRecordAPI + 'api/record/exportWorkRecord?deptNames=' + this.manageDep.join(',')
      url = url + '&searchBeginDate=' + searchBeginDate
      url = url + '&searchEndDate=' + searchEndDate
      url = url + '&searchText=' + this.searchText
      url = url + '&workPlan=' + this.filters.workPlan
      url = this.filters.workType ? url + '&workType=' + this.filters.workType : url
      url = url + '&pageNum=1'
      url = url + '&pageSize=10000'
      if (this.filters.completeStatus) {
        url = url + '&completeStatus=' + this.filters.completeStatus
      }
      switch (this.filters.state) { // 202106
        case 1:
          url = url + '&states=4'
          break
        case 2:
          url = url + '&states=4,5,6'
          break
        case 5:
          url = url + '&states=5,6'
          break
        case 6:
          url = url + '&states=6'
          break
      }
      console.log(url)
      window.open('/' + url)
    },
    getList () {
      console.log(this.manageDep)
      if (!this.filters.year || this.filters.year === '') {
        this.$message({
          message: '请选择查询年月',
          type: 'error'
        })
        return false
      }
      if (this.filters.month === 0) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 0, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 12, 0))
        this.searchText = this.filters.year + '年 全年'
      } else if (this.filters.month > 0 && this.filters.month <= 12) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), this.filters.month - 1, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), this.filters.month, 0))
        this.searchText = this.filters.year + '年' + this.filters.month + '月'
      } else if (this.filters.month === 13) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 0, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 2, 31))
        this.searchText = this.filters.year + '年 第一季度'
      } else if (this.filters.month === 14) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 3, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 5, 30))
        this.searchText = this.filters.year + '年 第二季度'
      } else if (this.filters.month === 15) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 6, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 8, 30))
        this.searchText = this.filters.year + '年 第三季度'
      } else if (this.filters.month === 16) {
        this.searchBeginDate = new Date(Date.UTC(parseInt(this.filters.year), 9, 1))
        this.searchEndDate = new Date(Date.UTC(parseInt(this.filters.year), 11, 31))
        this.searchText = this.filters.year + '年 第四季度'
      }
      let status = []
      switch (this.filters.state) {
        case 1:
          status = [4]
          break
        case 2:
          status = [4, 5, 6]
          break
        case 5:
          status = [5, 6]
          break
        case 6:
          status = [6]
          break
      }
      let url = 'api/record/queryWorkRecord'
      if (this.manageDep.indexOf('司领导') === -1) {
        this.manageDep.push('司领导')
      }
      let searchBeginDateMonth = this.searchBeginDate.getMonth() < 9 ? '0' + (this.searchBeginDate.getMonth() + 1) : this.searchBeginDate.getMonth() + 1
      let searchBeginDateDay = this.searchBeginDate.getDate() < 10 ? '0' + this.searchBeginDate.getDate() : this.searchBeginDate.getDate()
      let searchEndDateMonth = this.searchEndDate.getMonth() < 9 ? '0' + (this.searchEndDate.getMonth() + 1) : this.searchEndDate.getMonth() + 1
      let searchEndDateDay = this.searchEndDate.getDate() < 10 ? '0' + this.searchEndDate.getDate() : this.searchEndDate.getDate()
      let searchBeginDate = this.searchBeginDate.getFullYear() + '-' + searchBeginDateMonth + '-' + searchBeginDateDay
      let searchEndDate = this.searchBeginDate.getFullYear() + '-' + searchEndDateMonth + '-' + searchEndDateDay
      let para = {
        deptNames: this.filters.selectDep === '' ? this.manageDep : [this.filters.selectDep],
        // deptNames: this.manageDep,
        searchBeginDate: searchBeginDate,
        searchEndDate: searchEndDate,
        searchText: this.searchText,
        states: status,
        orderField: this.Sortkey,
        orderType: this.Isace,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        workPlan: this.filters.workPlan,
        workType: this.filters.workType,
        completeStatus: this.filters.completeStatus
      }

      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.workRecordAPI + url, para)
        .then(response => {
          this.listLoading = false
          this.prjs = response.data.result.records
          this.totalnum = response.data.result.total
          this.changeSizeFlag = false
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    del (id) {
      let ids = []
      if (id) {
        ids = [id]
      } else {
        ids = this.ids
      }
      if (ids.length > 0) {
        this.$confirm('确认删除该信息吗?', '提示', {
          type: 'error'
        }).then(() => {
          this.$http.post(this.$http.defaults.workRecordAPI + `api/record/removeRecord`, {ids: ids}).then(response => {
            if (response.data.success === true) {
              this.$message({
                message: '删除成功',
                type: 'success'
              })
            } else {
              console.log('删除失败:' + response.data.message)
              this.$message({
                message: '删除失败:' + response.data.message,
                type: 'error'
              })
            }
            this.getList()
          })
        }).catch(() => {
        })
      } else {
        this.$message({
          message: '请至少选择一条信息',
          type: 'danger'
        })
      }
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 352
      })
    },
    // getDics () {
    //   var _this = this
    //   this.$http
    //     .get(`/api/prj/dic`)
    //     .then(function (response) {
    //       _this.statusdic = response.data.statusdic
    //       _this.yearlist = response.data.yeardic
    //     })
    //     .catch(function (error) {
    //       console.log(error)
    //       _this.$message({
    //         message: '网络获取失败:' + error,
    //         type: 'error'
    //       })
    //     })
    // },
    stateText (id) {
      if (id === 4) {
        return '未上报司长'
      } else if (id === 5) {
        return '已上报司长'
      } else if (id === 6) {
        return '下发'
      }
    },
    completeStatusText (id) {
      switch (id) {
        case 1:
          return '未完成'
        case 2:
          return '完成'
        case 3:
          return '结束'
      }
    },
    // 检查用户身份
    checkRoles () {
      console.log('2执行checkRoles方法')
      if (localStorage.getItem('Roles').indexOf('ROLE_banshirenyuan') > -1) {
        this.myRole = 1
      }
      if (localStorage.getItem('Roles').indexOf('ROLE_chuzhang') > -1) {
        this.myRole = 2
      }
      if (localStorage.getItem('Roles').indexOf('ROLE_fusizhang') > -1) {
        this.myRole = 3
      }
      if (localStorage.getItem('Roles').indexOf('ROLE_sizhang') > -1) {
        this.myRole = 4
      }
      if (this.status) { // 填报开启时
        if (this.myRole === 1 || this.myRole === 2) {
          this.queryIfReported()
        }
      } else {
        this.getDeptList()
      }
      this.unitName = localStorage.getItem('unitName')
    },
    // 第一步：加载设置，查看目前是否开始填报，并返回工作月份
    loadSetup () {
      console.log('1执行loadSetup方法')
      this.setupFormLoading = true
      this.$http.get(this.$http.defaults.workRecordAPI + `api/config/getValueByKey?key=report-month`).then(response => {
        if (response.data.success === true) {
          if (response.data.result === '') {
            this.status = false
            this.setupForm.status = false
            this.isDown = true
            this.instruction = '提示：目前综合处未启动工作日志填报，点击设置填报状态和工作月份按钮，可开启指定月份的工作日志填报'
            let nowDate = new Date()
            this.myMonth = nowDate.getMonth() + 1 < 10 ? nowDate.getFullYear() + '-0' + (nowDate.getMonth() + 1) : nowDate.getFullYear() + '-' + (nowDate.getMonth() + 1)
            this.filters.year = nowDate.getFullYear().toString()
            this.filters.month = nowDate.getMonth() + 1
          } else {
            this.status = true
            this.setupForm.status = true
            this.setupForm.yearMonth = response.data.result
            this.myMonth = this.setupForm.yearMonth
            this.filters.year = this.myMonth.substr(0, 4)
            this.filters.month = parseInt(this.myMonth.substr(5, 2))
          }
          this.checkRoles()
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
        this.setupFormLoading = false
      })
      if (localStorage.getItem('Roles').indexOf('ROLE_chuzhang') > -1 && localStorage.getItem('unitName') === '综合处') {
        this.workRecordAdmin = true
      } else {
        this.workRecordAdmin = false
        this.$http
          .get(this.$http.defaults.workRecordAPI + `api/manageuser/getCurrentIfManageUser`)
          .then(response => {
            if (response.data.success) {
              this.workRecordAdmin = response.data.result
            } else {
              this.$message({
                message: '获取失败:' + response.data.message,
                type: 'error'
              })
            }
          })
          .catch(error => {
            if (error.status === 500) {
              this.$message({
                message: '网络获取失败:' + error,
                type: 'error'
              })
            }
          })
      }
    },

    loadSetupAdmin () {
      this.setupAdminFormLoading = true
      this.$http.get(this.$http.defaults.workRecordAPI + `api/manageuser/getManageUsers`).then(response => {
        if (response.data.success === true) {
          this.setupAdminForm.ids = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
        this.setupAdminFormLoading = false
      })
    }
  },
  mounted () {
    this.loadSetup()
    this.getDics('01', 'workTypeList')
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #alllist .wboxs{
    height:105px;
    padding-top:10px;
  }
  .el-table--border th, .el-table--border td {
    border-right: 1px solid #95B8E7;
  }
  .el-table th.is-leaf, .el-table td {
    border-bottom: 1px solid #95B8E7;
  }
  .work-record-warning-row{
    color:red
  }

</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .icon_flash{
    width: 20px;
    height: 20px;
    background-position: center center;
    background-repeat: no-repeat;
    background-size:contain;
    float: left;
    display: block;
    margin: 0 5px 0 0;
    background-image: url(../assets/icon_selection_gd1.gif)
  }
  .icon_flash1{
    width: 20px;
    height: 20px;
    background-position: center center;
    background-repeat: no-repeat;
    background-size:contain;
    float: left;
    display: block;
    margin: 0 5px 0 0;
    background-image: url(../assets/icon_selection_gd2.gif)
  }
  #recordLegent{
    float:right;
    margin-right: 10px;
  }
  #recordLegent div{
    float:left;
    line-height: 42px;
    font-size:var(--size14);
  }
  #recordLegent i{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: left;
    display: block;
    margin:5px 0px 0 3px;
  }
</style>
